package com.leo.ssh2.framework.service;



import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.leo.ssh2.framework.dto.User;

public class UserDAO implements IUserDAO {

	private SessionFactory sessionFactory;

	public UserDAO() {
	}

	public UserDAO(SessionFactory sessionFactory) {
		this.setSessionFactory(sessionFactory);
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void insert(User user) {
//		Session session = sessionFactory.openSession();
//		Transaction tx = session.beginTransaction();
//		session.save(user);
//		tx.commit();
//		session.close();
	}
	
	public User query(User userIn){
		  Session s = sessionFactory.openSession();
		  Query q = s.getNamedQuery("getUserById");
		  q.setString("id", userIn.getId());
		  if (q.list() == null || q.list().size() == 0) {
			  
			  return null;
		  } else {
			  return (User)q.list().get(0);
		  }
	}
}
